<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Upload;
use Think\Image;
class ContentController extends Controller{

   //显示内容
	public function listAction(){

          $this->display();
	}
    //添加内容
    public function  addAction(){
	    $this->display();
    }

        public  function  test(){
        $this->display();
        }

    // 图片上传
    public function up(){
        //实例化上传类
        $upload=new Upload();
        //最大值
        $upload->maxSize=2000000;
        $upload->exts=array('png','jpg','jpeg');
        $upload->savePath='/Cover/';
        $info=$upload->upload();
        if(!$info){
            $this->ajax($upload->getError());
        }else{
            // p($info);exit();
            // 上传成功，把上传好的信息返给js
            $img=$info['Filedata'];
            $savepath=$img['savepath'];
            $savename=$img['savename'];
            $savepath=str_replace('.','',$savepath);
            $path='Uploads' . $savepath .$savename;
            // p($path);exit;
            //实例化图片处理类
            $image=new Image();
            $image->open($path);
            //生成缩略图
            $image->thumb(260,180,6)->save($path);
            echo json_encode($path);
            exit;
        }
    }
}